package com.sm.chatinputlibrary;

import android.app.Activity;
import android.content.Intent;


import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.zhihu.matisse.Matisse;

/**
 * created by zhud on 2019/8/14
 */
public class ChatInputResultFragment extends Fragment {
    // 拍照回传码
    public final static int CAMERA_REQUEST_CODE = 4567;
    // 相册选择回传吗
    public final static int GALLERY_REQUEST_CODE = 4568;
    //剪裁图片
    public final static int FILE_REQUEST_CODE = 4569;

    private OnChatInputResultListener onChatInputResultListener;

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
                case CAMERA_REQUEST_CODE:
                    // 获得图片 imageUri
                    if (onChatInputResultListener != null) {
                        onChatInputResultListener.onCameraResult();
                    }
                    break;
                case GALLERY_REQUEST_CODE:
                    // 获取图片
                    if (onChatInputResultListener != null) {
                        onChatInputResultListener.onPictureResult(Matisse.obtainResult(data));
                    }
                    break;
                case FILE_REQUEST_CODE:
                    // 获取文件
                    if (onChatInputResultListener != null) {
                        //onChatInputEventListener.onSelectedFile(data.getData());
                    }
                    break;
            }
        }
    }

    public void prepareRequest(FragmentActivity activity, OnChatInputResultListener onChatInputResultListener) {
        this.onChatInputResultListener = onChatInputResultListener;
        activity.getSupportFragmentManager().beginTransaction().add(this, activity.getClass().getName()).commit();
    }
}